package com.example.mybank.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.mybank.entity.Statement;
import com.example.mybank.mapper.StatementMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/statement")
public class StatementController {

    @Autowired
    StatementMapper statementMapper;

    // 管理员：获取所有流水
    @GetMapping("/all")
    public List<Statement> getAll(){
        return statementMapper.selectList(null);
    }


    // 用户员：获取某账户的流水
    @GetMapping("/account/{accountID}")
    public List<Statement> getByAccount(@PathVariable("accountID") int accountID){
        QueryWrapper<Statement> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("account",accountID);
        return statementMapper.selectList(queryWrapper);
    }

    // 用户员：获取用户的流水
    @GetMapping("/users/{usersID}")
    public List<Statement> getByUsers(@PathVariable("usersID") int usersID){
        QueryWrapper<Statement> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("users",usersID);
        return statementMapper.selectList(queryWrapper);
    }

}
